$(function() {
	$("#header").load('header.html', function() {
		loadHeader(1)
	});
	$("#footer").load('footer.html', function() {});
	$("#tab").load('tab.html', function() {});

	var counter = 0;
	var pageStart = 0;
	var pageSize = 8;
    var _url = decodeURI(window.location.search)
    var condition = _url.split('=')[1]
	getData(pageStart, pageSize);

	$(document).on('click', '.btn-danger', function() {
		getData(pageStart, pageSize);
	});
	$(document).on('click', '#search_button', function() {
		getData(pageStart, pageSize);
	});

	function getData(offset, size) {
		$.ajax({
			url: host + '/MtmlAPI/DoctorList',
			type: 'post',
			dataType: 'JSON',
			data: {
				cid: cid,
				HosID: 0,
				index: ++pageStart,
				isTop: false,
				size: 8,
				condition:condition
			},

			success: function(res) {
				var docs = res.data
				var sum = docs.length;
				if(res.state) {
					var html = ''
					$.each(docs, function(i, doc) {
						var tagHtml = ''
						var tagArr = doc.Tags.split('|').slice(0, -1)
						
						$.each(tagArr, function(j, tag) {
							tagHtml += `<div>${tag}</div>`
						})
						html += `<li onclick="location.href='doctor-produce.html?mid=${doc.mid}'">
									<div class='doc-list-img' style='background-image:url(${doc.HeadImage});'></div>
									<div class="doc-list-name">${doc.RealName}</div>
									<div class="doc-list-intic">${doc.HospitalName}</div>
									<div class="doc-list-pro">${tagHtml}</div>
								</li>`
					});
					$('.doctor-list').append(html)
					if((offset * size) > sum) {
						$(".btn-danger").hide();
					} else {
						$(".btn-danger").show();
					}
				} else {

				}
			},
			error: function() {}
		});
	}
	
})